package com.yami.shop.api.controller;

import com.yami.shop.api.config.DateUtil;
import com.yami.shop.api.config.HttpClient;
import com.yami.shop.api.config.ParamBuilder;
import com.yami.shop.api.config.SignHelper;
import com.yami.shop.bean.meituan.CheckRequest;
import com.yami.shop.bean.meituan.CreateShop;
import com.yami.shop.bean.meituan.OpenApiConfig;
import com.yami.shop.bean.meituan.RequestConstant;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class CreateShopController {

    @PostMapping("/createShop")
    public  void createShop() throws Exception {
        String appkey = OpenApiConfig.TEST_APP_KEY;
        String secret = OpenApiConfig.TEST_SECRET;
        String res=null;
        CreateShop request = buildMockRequest(appkey);

        Map<String, String> params = ParamBuilder.convertToMap(request);
        String sign = SignHelper.generateSign(params, secret);

        params.put("sign", sign);

        try {
            res = HttpClient.post(RequestConstant.CREATE_SHOP, params);
        } catch (Exception e) {
            throw e;
        }
    }

    private CreateShop buildMockRequest(String appkey) {
        CreateShop request = new CreateShop();
        request.setAppkey(appkey);
        request.setTimestamp(Long.valueOf(DateUtil.unixTime()));
        /**
         * 设置版本
         */
        request.setVersion("1.0");


        //设置门店ID
        request.setShopId("xeld-2");
        //设置店铺名字
        request.setShopName("慕莎蛋糕");
        //设置一级类别
        request.setCategory(270);
        //设置二级类别
        request.setSecondCategory(270001);
        //设置店主
        request.setContactName("周涛");
        //设置联系电话
        request.setContactPhone("15997195644");
        //联系邮箱
        //request.setContactEmail("315673187@qq.com");
        //设置地址
        request.setShopArress("湖北省襄阳市樊城区星火公寓");
        //门牌号
        //request.setShopAdressDetail("A43-1");
        //设置经度
        request.setShopIng(112154249);
        //设置纬度
        request.setShopLat(32052031);
        request.setCoordinateType(0);
        request.setBusinessHours("[{\"beginTime\":\"07:00\",\"endTime\":\"21:00\"}]");
        /**
         * 设置配送服务编码
         *
         * 光速达:4001
         * 快速达:4011
         * 及时达:4012
         * 集中送:4013
         * 当天达:4021
         */
        request.setDeliveryServiceCode("4001");


        return request;
    }


}
